package com.reactim.message.entity;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 会话实体类
 */
@Data
@Document(collection = "conversations")
@CompoundIndexes({
    @CompoundIndex(name = "user_type_idx", def = "{'participants': 1, 'type': 1}"),
    @CompoundIndex(name = "user_update_time_idx", def = "{'participants': 1, 'lastMessageTime': -1}")
})
public class Conversation {
    
    @Id
    private String id;
    
    @Indexed(unique = true)
    private String conversationId;      // 会话唯一ID
    
    private ConversationType type;      // 会话类型
    
    @Indexed
    private List<Long> participants;    // 参与者用户ID列表
    
    private Long groupId;               // 群组ID（群聊时使用）
    
    private String lastMessageId;       // 最后一条消息ID
    
    private String lastMessageContent;  // 最后一条消息内容预览
    
    @Indexed
    private LocalDateTime lastMessageTime; // 最后消息时间
    
    private Long messageCount;          // 消息总数
    
    private LocalDateTime createdAt;    // 创建时间
    
    private LocalDateTime updatedAt;    // 更新时间
    
    /**
     * 会话类型枚举
     */
    public enum ConversationType {
        PRIVATE,        // 私聊
        GROUP,          // 群聊
        SYSTEM          // 系统会话
    }
}